package cn.zsc.netdisk.mapper;

import cn.zsc.netdisk.pojo.Share;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

/**
 * @author ccying
 * @date 2021/3/9
 */
@Component
@Mapper
public interface ShareMapper {
    /**
     * 查询所有分享用户
     * @return 分享用户数组
     * */
    @Select("select distinct uid from t_share")
    String[] findAllShareUid();

    /**
     * 根据url查询分享链接
     * @param url 分享url
     * @return 分享链接信息
     * */
    @Select("select name,url,password from t_share where url=#{url}")
    Share findShareByUrl(String url);

    /**
     * 删除所有分享链接记录
     * @throws Exception 执行sql语句可能抛出异常
     * */
    @Delete("delete from t_share")
    void deleteAll() throws Exception;

    /**
     * 增加一条文件分享链接记录
     * @param share 文件分享链接信息
     * @throws Exception 执行sql语句可能抛出异常
     * */
    @Insert("insert into t_share(uid,name,url,password,created) value(#{share.uid},#{share.name},#{share.url},#{share.password},now())")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void add(@Param("share") Share share) throws Exception;
}
